﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fhe
{
  using math;
  namespace physics
  {
    public class PointMass
    {
      public Vec2 Position { get; set; }

      public Vec2 Velocity { get; set; }

      public double Mass { get; set; }

      public static Vec2 Gravity { get; set; }

      static PointMass()
      {
        Gravity = new Vec2(0, -10);
      }

      public PointMass()
      {
        Mass = 1;
      }

      private Vec2 Force;

      private double MaxSpeed = 10;

      public void ApplyForce(Vec2 f)
      {
        Force += f;
      }

      public void Update(TimeSpan ts)
      {
        double dt = ts.TotalSeconds;
        if (Mass > 0)
        {
          Velocity += (Force / Mass + Gravity) * dt;
        }
        if (Velocity.Length() > MaxSpeed)
        {
          Velocity = Velocity.Normalize() * MaxSpeed;
        }
        Position += Velocity * dt;
        Force = new Vec2();
      }
    }
  }
}